﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace Listecky
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        static private string testCaseName = "../../TestCase.qa";
        private DataSource source;
        private Storyboard switchAnswer;
        int mode;

        public MainWindow()
        {
            source = new DataSource();
            source.Load(testCaseName);
            DataContext = source;

            InitializeComponent();
            switchAnswer =
                    (Storyboard)this.Resources["SwitchAnswer"];
            mode = 0;
            AddQuestion.Visibility = DelQuestion.Visibility = Visibility.Hidden;
        }

        private void Storyboard_Completed(object sender, EventArgs e)
        {
            switchAnswer.Begin(Listok, HandoffBehavior.SnapshotAndReplace);
            Question.Visibility = Question.Visibility == Visibility.Hidden ? Visibility.Visible : Visibility.Hidden;
            Answer.Visibility = Question.Visibility == Visibility.Hidden ? Visibility.Visible : Visibility.Hidden; ;
        }

        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            mode = 1 - mode;
            ShowAnswer.IsEnabled = !ShowAnswer.IsEnabled;
            btn.Content = ShowAnswer.IsEnabled ? "Edit" : "StopEditing";
            Answer.SetValue(Grid.RowProperty, mode == 0 ? 0 : 1);
            Answer.SetValue(Grid.RowSpanProperty, mode == 0 ? 2 : 1);
            Question.SetValue(Grid.RowSpanProperty, mode == 0 ? 2 : 1);
            Answer.Visibility = mode == 0 ? Answer.Visibility = Visibility.Hidden : Visibility.Visible;
            Question.Visibility = Visibility.Visible;
            AddQuestion.Visibility = DelQuestion.Visibility = Answer.Visibility;
        }

        private void AddQuestion_Click(object sender, RoutedEventArgs e)
        {
            source.AddEmptyModel();
        }

        private void NextQuestion_Click(object sender, RoutedEventArgs e)
        {
            source.SetNext();
        }

        private void DelQuestion_Click(object sender, RoutedEventArgs e)
        {
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            source.Save(testCaseName);
        }

        private void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            source.Load(testCaseName);
        }

        private void RandomQuestion_Click(object sender, RoutedEventArgs e)
        {
            source.SetRandom();
        }

        private void Close(object sender, EventArgs e)
        {
            source.Close();
        }
    }
}
